﻿using RFID_EX_WineSecurity.Core;
using RFID_EX_WineSecurity.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RFID_EX_WineSecurity {
    public partial class SettingForm : Form {
        public SettingForm() {
            InitializeComponent();
        }

        private void SettingForm_Load(object sender, EventArgs e) {
            InitView();
        }

        private void InitView() {
            this.Text = GlobalVariable.APP_NAME+"-->设置";
            string[] baudRates = new string[] {
                "2400","4800","7200","9600","14400","19200","38400","57600","115200"
            };
            cb_BaudRate.Items.AddRange(baudRates);
            cb_BaudRate.SelectedText = RFIDReader.BaudRate.ToString();
        }


        /**
         * 界面
         * ***********************************************************/
        private delegate void SetBottomMessageDelegate(string message);
        private void SetBottomMessage(string message) {
            if (lb_result.InvokeRequired) {
                this.Invoke(new SetBottomMessageDelegate(SetBottomMessage), message);
            } else {
                lb_result.Text = message;
            }
        }

        /**
         * 事件
         * ***********************************************************/
        
        private void rbtn_on_CheckedChanged(object sender, EventArgs e) {
            
        }

        private void cbx_yellow_CheckedChanged(object sender, EventArgs e) {

        }

        private void cbx_green_CheckedChanged(object sender, EventArgs e) {

        }

        private void btn_Go_Click(object sender, EventArgs e) {
            string timeStr = tb_noiceTime.Text.Trim();
            byte timeHex = 0;
            try {
                timeHex = Convert.ToByte(timeStr);
                if (timeHex < 0) {
                    throw new Exception("时长不得小于0");
                }
            } catch {
                SetBottomMessage("只允许输入0-255的整数");
            }
            RFIDReader.rf_beep(RFIDReader.IcDev, timeHex);
        }
    }
}
